import requests
import json


def getaddress(address):
    API_KEY = "3ni6ns4chmwohGDakVc7LTPG"
    SECRET_KEY = "cNGqFu5RUOVKGKfuCzQySHdLAM6ieYZ5"

    url = "https://aip.baidubce.com/oauth/2.0/token"
    params = {"grant_type": "client_credentials", "client_id": API_KEY, "client_secret": SECRET_KEY}
    access_token = str(requests.post(url, params=params).json().get("access_token"))

    url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/address?access_token=" + access_token
    payload = json.dumps({
        "text": address
    })
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data=payload)

    str1 = str(response.text)
    print(str1)

# address='广东省东莞市松山湖园区科苑路3号 佳禾智能科技股份有限公司'
address='越南, 老板龙街1号'
getaddress(address)